<template>
	<view class="con">
		<!-- 列表 -->
		<view class="list">
			<view class="list_li flex flex_between" v-for="(item,index) in list" :key="index" @click="goIndexDetail(item)">
				<view class="list_liz">{{item.title}}</view>
				<image class="list_liy" src="/static/jiant.png" mode="widthFix"></image>
			</view>
		</view>
	</view>
</template>

<script>
  import {
    getArticleList,//信息列表(公告、常见问题)
  } from '@/request/api.js'
	export default {
		data() {
			return {
        openid: uni.getStorageSync('openid'),
        type:'gg', //gg 公告; wt 常见问题
        page:1,
        list:[],
        total:0,//总共的数量
        pagesizes:15//每页数量
      }
		},
		onLoad(options) {
      console.log(options)
      this.type = options.type
      if(options.type==="gg"){
        uni.setNavigationBarTitle({
          title:'官方公告'
        })
      }else if(options.type==="wt"){
        uni.setNavigationBarTitle({
          title:'常见问题'
        })
      }
      this.getArticleListFun()
		},
    onShow() {
      this.isLogin = uni.getStorageSync('isLogin') || 1
      if (this.isLogin === 1) {
      	console.log('未授权登录')
        uni.hideShareMenu()
      }else{
        uni.showShareMenu({
        	withShareTicket: true,
        	menus: ["shareAppMessage", "shareTimeline"]
        })
      }
    },
    onReachBottom() {
      let totolPage =Math.ceil(this.total / this.pagesizes) 
      console.log('总共多少页')
      console.log(totolPage)
      if(this.page<=totolPage){
        this.loadMore(); // 当上拉时加载更多数据
      }
    },
		methods: {
      // 获取列表
      getArticleListFun(){
        getArticleList(this.openid,this.type,this.page).then(res=>{
          console.log('信息列表(公告、常见问题)')
          console.log(res)
          this.total = Number(res.data.total);
          this.pagesizes = Number(res.data.pagesizes);
          let listRe = res.data.arrList
          if(listRe.length>0){
            this.list = this.list.concat(listRe);
          }
        })
      },
      // 加载更多
      loadMore(){
        this.page = this.page+1
        this.getArticleListFun()
      },
      // 跳转详情页
      goIndexDetail(item){
        console.log('跳转详情页')
        console.log(item)
        uni.navigateTo({
          url:"/packageA/index/detail2?id="+item.id+'&title='+item.title
        })
      },
		},
    
    // 分享微信好友
    onShareAppMessage(event) {
    	console.log(event);
        return {
        	title: '陌上未来，没有概率做了就赚',
        	path: '/pages/index/index?pid=' + uni.getStorageSync('userInfo').id,
        	// imageUrl: imageUrl
        }
    },
    //分享到朋友圈
    onShareTimeline(event) {
    	console.log(event);
    	return {
    		title: '陌上未来，没有概率做了就赚',
    		path: '/pages/index/index?pid=' + uni.getStorageSync('userInfo').id,
    		query: 'pid=' + uni.getStorageSync('userInfo').id,
    		// imageUrl: imageUrl
    	}
    }
	}
</script>

<style scoped lang="scss">
	.con {
		.list {
			width: 100%;
			height: auto;

			.list_li {
				width: 100%;
				height: 104rpx;
				border-radius: 20rpx;
				background-color: rgba(255, 255, 255, 1);
				padding: 0 30rpx;
				// margin-top: 20rpx;
				box-sizing: border-box;
        margin-bottom: 30rpx;
				.list_liz {
          color: #101010;
          font-size: 28rpx;
          height: 30rpx;
          line-height: 30rpx;
          overflow: hidden;
          width: 90%;
				}

				.list_liy {
					width: 24rpx;
					height: auto;
				}
			}
		}
	}
</style>